home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
DEMON
/
RISCOS2
/
TCP_131S.ARC
/
c
/
Terminal
< prev
next >
Wrap
Text File
|
1994-03-06
|
32KB
|
1,199 lines
/* cu-notic.txt NCSA Telnet version 2.2C 2/3/89
Notice:
Portions of this file have been modified by
The Educational Resources Center of Clarkson University.
All modifications made by Clarkson University are hereby placed
in the public domain, provided the following statement remain in
all source files.
"Portions Developed by the Educational Resources Center,
Clarkson University"
Bugs and comments to bkc@omnigate.clarkson.edu
bkc@clgw.bitnet
Brad Clements
Educational Resources Center
Clarkson University
*/
/*
*
* Virtual Screen Kernel Emulation Routines
* (vsem.c)
*
* National Center for Supercomputing Applications
* by Gaige B. Paulsen
*
* This file contains the private emulation calls for the NCSA
* Virtual Screen Kernel.
*
* Version Date Notes
* ------- ------ ---------------------------------------------------
* 0.01 861102 Initial coding -GBP
* 0.10 861111 Added/Modified VT emulator -GBP
* 0.50 861113 First compiled edition -GBP
* 2.1 871130 NCSA Telnet 2.1 -GBP
* 2.2 880715 NCSA Telnet 2.2 -GBP
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bbc.h"
#include "global.h"
#include "menu.h"
#include "os.h"
#include "misc.h"
#include "session.h"
#include "sprite.h"
#include "wimp.h"
#include "wimpt.h"
#include "win.h"
#include "dbox.h"
#include "template.h"
#include "cmdparse.h"
#include "Terminal.h"
/* Adam - 02-Feb-94 */
#include "xferrecv.h"
#include "werr.h"
#define OS_ChangedBox 0x0000005a
BOOL scale = FALSE;
typedef struct
{
int flag;
wimp_box box;
}
change_box;
static void Window_Scroll(Terminal *);
static os_error *Changed_Box(int, change_box **);
/* Adam - 02-Feb-94 */
static void Process_Import(wimp_eventstr *Event, Terminal *Window);
static char *leafname(char *s);
#define XtoWork(x) ((x) << 1)
#define YtoWork(y) ((y) << 2)
int keymap(int raw, char *buffer, int c)
{
if (raw)
{
switch (c)
{
case 0x181: /* F1 */
strcpy(buffer, "\033OP");
return(3);
case 0x182: /* F2 */
strcpy(buffer, "\033OQ");
return(3);
case 0x183: /* F3 */
strcpy(buffer, "\033OR");
return(3);
case 0x184: /* F4 */
strcpy(buffer, "\033OS");
return(3);
case 0x1CD: /* Insert */
strcpy(buffer, "\033[1~");
return(4);
case 0x1E: /* Home */
strcpy(buffer, "\033[2~");
return(4);
case 0x19F: /* Page Up */
strcpy(buffer, "\033[3~");
return(4);
case 0x7F: /* Delete */
strcpy(buffer, "\033[4~");
return(4);
case 0x18B: /* Copy */
strcpy(buffer, "\033[5~");
return(4);
case 0x19E: /* Page Down */
strcpy(buffer, "\033[6~");
return(4);
case 0x18F: /* Up Arrow */
strcpy(buffer, "\033[A");
return(3);
case 0x18E: /* Down Arrow */
strcpy(buffer, "\033[B");
return(3);
case 0x18D: /* Right Arrow */
strcpy(buffer, "\033[C");
return(3);
case 0x18C: /* Left Arrow */
strcpy(buffer, "\033[D");
return(3);
case 0x18A: /* Tab */
strcpy(buffer, "\0x09");
return(1);
default:
if (c < 0x7F)
{
*buffer = c;
return(1);
}
break;
}
}
else
{
switch (c)
{
case '\r':
case '\n':
strcpy(buffer, "\r\n");
return(2);
default:
if (c < 0x7F)
{
*buffer = c;
return(1);
}
break;
}
}
return(0);
}
static void Redo_Window(Terminal *Window, wimp_redrawstr r, BOOL more)
{
BOOL more_to_do = more;
wimp_redrawstr new_r = r;
sprite_factors factors;
sprite_pixtrans pixtrans[256];
wimp_readpixtrans(Window->Sprite.Area, &Window->Sprite.id, &factors, pixtrans);
if (scale)
{
factors.xdiv *= Window->X_Div_Mult;
factors.ydiv *= Window->Y_Div_Mult;
factors.xmag *= Window->X_Mag_Mult;
factors.ymag *= Window->Y_Mag_Mult;
}
while (more_to_do)
{
if (scale)
sprite_put_scaled(Window->Sprite.Area, &Window->Sprite.id, 0, r.box.x0, r.box.y0, &factors, pixtrans);
else
sprite_put_scaled(Window->Sprite.Area, &Window->Sprite.id, 0, r.box.x0 - r.scx, r.box.y1 - 768 - r.scy, &factors, pixtrans);
wimp_get_rectangle(&new_r, &more_to_do);
}
}
static void Redraw_Window(Terminal *Window, wimp_w handle)
{
BOOL more;
wimp_redrawstr r;
wimp_winfo winfo;
winfo.w = handle;
wimp_get_wind_info(&winfo);
Window->X_Div_Mult = winfo.info.ex.x1 - winfo.info.ex.x0;
Window->Y_Div_Mult = winfo.info.ex.y1 - winfo.info.ex.y0;
Window->X_Mag_Mult = winfo.info.box.x1 - winfo.info.box.x0;
Window->Y_Mag_Mult = winfo.info.box.y1 - winfo.info.box.y0;
r.w = handle;
wimp_redraw_wind(&r, &more);
if (more)
Redo_Window(Window, r, more);
}
static void Open_Window(Terminal *Window, wimp_openstr *o)
{
if (scale)
{
o->x = 0;
o->y = 0;
}
wimp_open_wind(o);
if (Window->Old_X != (o->box.x1 - o->box.x0) ||
Window->Old_Y != (o->box.y1 - o->box.y0))
{
Redraw_Window(Window, o->w);
Window->Old_X = o->box.x1 - o->box.x0;
Window->Old_Y = o->box.y1 - o->box.y0;
}
}
void Update_Window(Terminal *Window, wimp_redrawstr r)
{
wimp_redrawstr new_r = r;
BOOL more;
wimp_update_wind(&new_r, &more);
if (more)
Redo_Window(Window, new_r, more);
}
void Window_Reset(Terminal *Window)
{
int i;
Window->x = 0;
Window->y = 0;
Window->Top = 0;
Window->Bottom = 23;
Window->Attr = ATTR_NORMAL;
Window->Cursor = 1;
Window->G0 = 0;
Window->G1 = 1;
Window->Parmptr = 0;
for (i = 0; i < 6; i++)
Window->Parms[i] = -1;
for (i = 0; i < SCREEN_WIDTH; i++)
Window->Tabs[i] = (i % TAB_STOPS) ? ' ' : 'x';
Window->Tabs[SCREEN_WIDTH - 1] = 'x';
bbc_vduq(28, 0, 23, 79, 0);
bbc_vduq(17, 128 + Window->Background[ATTR_NORMAL]);
bbc_vduq(17, Window->Foreground[ATTR_NORMAL]);
bbc_cls();
}
void Window_Write(Terminal *Window, char *s, int n)
{
sprite_state State;
wimp_redrawstr r;
register int Escflg;
change_box *Box;
int i, cx, cy;
if (Window == NULL)
return;
if (Window->Record != NULL)
fwrite(s, 1, n, Window->Record);
sprite_outputtosprite(Window->Sprite.Area, &Window->Sprite.id, Window->Save_Area, &State);
Changed_Box(1, &Box);
Changed_Box(2, &Box);
Escflg = Window->Esc_Flag;
if (Window->Cursor)
{
cx = Window->x * 16;
cy = 768 - Window->y * 32 - 28;
bbc_vduq(25, 4, cx % 256, cx / 256,
cy % 256, cy / 256);
bbc_vduq(25, 102, (cx + 16) % 256, (cx + 16) / 256,
(cy + 24) % 256, (cy + 24) / 256);
}
bbc_vduq(17, 128 + Window->Background[ATTR_NORMAL]);
bbc_vduq(17, Window->Foreground[ATTR_NORMAL]);
while (n > 0)
{
while ((Escflg == ESCAPE_NONE) && (n > 0) && (*s < 32))
{
switch (*s)
{
case 0x1b: /* \E ... */
Escflg = ESCAPE_FOUND;
break;
case 0x07: /* ^G - bel */
bbc_vdu(7);
break;
case 0x08: /* ^H - cub1 */
Window->x--;
Window_Scroll(Window);
break;
case 0x0e:
Window->Charset = 1;
break;
case 0x0f:
Window->Charset = 0;
break;
case 0x09: /* ^I - ht */
for (i = Window->x + 1; i < SCREEN_WIDTH; i++)
{
if (Window->Tabs[i] == 'x')
{
Window->x = i;
break;
}
}
Window_Scroll(Window);
break;
case 0x0d: /* ^M - cr */
Window->x = 0;
bbc_vdu(13);
break;
case 0x0a: /* ^J - lf */
Window->y++;
Window->x = 0;
if (Window->y > Window->Bottom)
Window->y = Window->Bottom;
bbc_vdu(10);
bbc_vdu(13);
break;
default:
break;
}
s++;
n--;
}
bbc_vduq(17, 128 + Window->Background[Window->Attr]);
bbc_vduq(17, Window->Foreground[Window->Attr]);
while ((n > 0) && (Escflg == ESCAPE_NONE) && (*s >= 32))
{
bbc_vdu(*s);
Window->x++;
Window_Scroll(Window);
s++;
n--;
}
bbc_vduq(17, 128 + Window->Background[ATTR_NORMAL]);
bbc_vduq(17, Window->Foreground[ATTR_NORMAL]);
while ((n > 0) && (Escflg == ESCAPE_FOUND))
{
switch (*s)
{
case 0x08:
Window->x--;
Window_Scroll(Window);
break;
case '[': /* \E[ ... */
Window->Parmptr = 0;
for (i = 0; i < 6; i++)
Window->Parms[i] = -1;
Escflg = ESCAPE_1;
break;
case '7': /* \E7 - sc */
Window->Save_x = Window->x;
Window->Save_y = Window->y;
Window->Save_Attr = Window->Attr;
Escflg = ESCAPE_NONE;
break;
case '8': /* \E8 - rc */
Window->x = Window->Save_x;
Window->y = Window->Save_y;
Window->Attr = Window->Save_Attr;
Escflg = ESCAPE_NONE;
break;
case 'c': /* \Ec ... */
Window_Reset(Window);
Escflg = ESCAPE_NONE;
break;
case 'D': /* \ED */
Window->y++;
Window_Scroll(Window);
Escflg = ESCAPE_NONE;
break;
case 'E': /* \EE */
Window->y++;
Window->x = 0;
Window_Scroll(Window);
Escflg = ESCAPE_NONE;
break;
case 'M': /* \EM - ri */
Window->y--;
Window_Scroll(Window);
Escflg = ESCAPE_NONE;
break;
case '>': /* \E> - rmkx */
if (Window->Session)
Window->Session->keypad = 0;
else
Window->keypad = 0;
Escflg = ESCAPE_NONE;
break;
case '=': /* \E= - smkx */
if (Window->Session)
Window->Session->keypad = 1;
else
Window->keypad = 1;
Escflg = ESCAPE_NONE;
break;
case '(': /* \E( ... */
Escflg = ESCAPE_3;
break;
case ')': /* \E) ... */
Escflg = ESCAPE_4;
break;
case '#': /* \E# ... */
Escflg = ESCAPE_5;
break;
case 'H': /* \EH - hts */
Window->Tabs[Window->x] = 'x';
Escflg = ESCAPE_NONE;
break;
default:
Escflg = ESCAPE_NONE;
break;
}
s++;
n--;
}
while ((Escflg == ESCAPE_1) && (n > 0))
{
switch (*s)
{
case 0x08:
Window->x--;
Window_Scroll(Window);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (Window->Parms[Window->Parmptr] < 0) Window->Parms[Window->Parmptr] = 0;
Window->Parms[Window->Parmptr] *= 10;
Window->Parms[Window->Parmptr] += *s - '0';
break;
case '?': /* \E[? ... */
Window->Parms[Window->Parmptr++] = -2;
break;
case ';': /* \E[nn; ... */
Window->Parmptr++;
break;
case 'A': /* \E[%p1%dA - cuu, cuu1 */
if (Window->Parms[0] < 1)
Window->y--;
else
Window->y -= Window->Parms[0];
Window_Scroll(Window);
Escflg = ESCAPE_NONE;
break;
case 'B': /* \E[%p1%dB - cud */
if (Window->Parms[0] < 1)
Window->y++;
else
Window->y += Window->Parms[0];
Window_Scroll(Window);
Escflg = ESCAPE_NONE;
break;
case 'C': /* \E[%p1%dC - cuf, cuf1 */
if (Window->Parms[0] < 1)
Window->x++;
else
Window->x += Window->Parms[0];
Window_Scroll(Window);
Escflg = ESCAPE_NONE;
break;
case 'D': /* \E[%p1%dD - cub, cub1 */
if (Window->Parms[0] < 1)
Window->x--;
else
Window->x -= Window->Parms[0];
Window_Scroll(Window);
Escflg = ESCAPE_NONE;
break;
case 'f': /* \E[%i%p1%d;%p2%df */
case 'H': /* \E[%i%p1%d;%p2%dH - cup */
Window->x = Window->Parms[1] - 1;
Window->y = Window->Parms[0] - 1;
if (Window->x < 0) Window->x = 0;
if (Window->x > 79) Window->x = 79;
if (Window->y < Window->Top) Window->y = Window->Top;
if (Window->y > Window->Bottom) Window->y = Window->Bottom;
bbc_vduq(31, Window->x, Window->y);
Escflg = ESCAPE_NONE;
break;
case 'K': /* \E[K - e1*/
switch (Window->Parms[0])
{
case -1:
case 0:
bbc_vduq(23,8,5,6,0,0,0,0,0,0);
break;
case 1:
bbc_vduq(23,8,4,5,0,0,0,0,0,0);
break;
case 2:
bbc_vduq(23,8,4,6,0,0,0,0,0,0);
break;
default:
Escflg = ESCAPE_NONE;
break;
}
Escflg = ESCAPE_NONE;
break;
case 'J': /* \E[J - ed */
switch (Window->Parms[0])
{
case -1:
case 0:
bbc_vduq(23,8,5,10,0,0,0,0,0,0);
break;
case 1:
bbc_vduq(23,8,0,5,0,0,0,0,0,0);
break;
case 2:
bbc_vduq(23,8,0,10,0,0,0,0,0,0);
break;
default:
Escflg = ESCAPE_NONE;
break;
}
Escflg = ESCAPE_NONE;
break;
case 'm': /* \E[nnm - smso, rmso, smul, */
/* rmul, bold, rev, blink */
switch (Window->Parms[0])
{
case -1:
case 0: /* \E[0m - rmso, rmul */
Window->Attr = ATTR_NORMAL;
break;
case 1: /* \E[1m - bold */
Window->Attr = ATTR_BOLD;
break;
case 4: /* \E[4m - smul */
Window->Attr = ATTR_UNDER;
break;
case 5: /* \E[5m - blink */
Window->Attr = ATTR_BLINK;
break;
case 7: /* \E[7m - smso, rev */
Window->Attr = ATTR_REVERSE;
break;
default:
break;
}
Escflg = ESCAPE_NONE;
break;
case 'L': /* \E[L - il1 */
if (Window->Parms[0] < 1) Window->Parms[0] = 1;
bbc_vduq(28, 0, Window->Bottom, 79, Window->y);
for (i = 0; i < Window->Parms[0]; i++)
bbc_vduq(23,7,0,2,0,0,0,0,0,0);
bbc_vduq(28,0,Window->Bottom,79,Window->Top);
bbc_vduq(31, Window->x, Window->y);
Escflg = ESCAPE_NONE;
break;
case 'M': /* \E[M - dl1 */
if (Window->Parms[0] < 1) Window->Parms[0] = 1;
bbc_vduq(28, 0, Window->Bottom, 79, Window->y);
for (i = 0; i < Window->Parms[0]; i++)
bbc_vduq(23,7,0,3,0,0,0,0,0,0);
bbc_vduq(28, 0, Window->Bottom, 79, Window->Top);
bbc_vduq(31, Window->x, Window->y);
Escflg = ESCAPE_NONE;
break;
case 'P': /* \E[P */
if (Window->Parms[0] < 1) Window->Parms[0] = 1;
bbc_vduq(28, Window->x, Window->y, 79, Window->y);
for (i = 0; i < Window->Parms[0]; i++)
bbc_vduq(23,7,0,1,0,0,0,0,0,0);
bbc_vduq(28, 0, Window->Bottom, 79, Window->Top);
bbc_vduq(31, Window->x, Window->y);
Escflg = ESCAPE_NONE;
break;
case 'r': /* \E[r */
if (Window->Parms[0] < 0)
Window->Top = 0;
else
Window->Top = Window->Parms[0] - 1;
if (Window->Parms[1] < 0)
Window->Bottom = 23;
else
Window->Bottom = Window->Parms[1] - 1;
if (Window->Top < 0) Window->Top = 0;
if (Window->Top > 22) Window->Top = 22;
if (Window->Bottom < 1) Window->Bottom = 23;
if (Window->Bottom > 23) Window->Bottom = 23;
Window->x = 0;
Window->y = Window->Top;
bbc_vduq(28, 0, Window->Bottom , 79, Window->Top);
bbc_vduq(31, Window->x, Window->y);
Escflg = ESCAPE_NONE;
break;
case 'h': /* \E[h - cnorm, cvvis */
Window->Cursor = 1;
Escflg = ESCAPE_NONE;
break;
case 'l': /* \E[l - civis */
Window->Cursor = 0;
Escflg = ESCAPE_NONE;
break;
case 'g': /* \E[g - tbc */
if (Window->Parms[0] == 3)
{
for (i = 0; i < SCREEN_WIDTH; i++)
Window->Tabs[i] = ' ';
}
else
{
if (Window->Parms[0] == 0 || Window->Parms[0] < 0)
Window->Tabs[Window->x] = ' ';
}
Escflg = ESCAPE_NONE;
break;
default:
Escflg = ESCAPE_NONE;
break;
}
s++;
n--;
}
while ((Escflg == ESCAPE_3) && (n > 0))
{
switch (*s)
{
case 0x08:
Window->x--;
Window_Scroll(Window);
break;
case 'A': /* \E(A */
case 'B': /* \E(B - font0 */
case '1': /* \E(1 */
Window->G0 = 0;
/*
if (!Window->Charset)
Window->Attrib = VSnotgraph(Window->Attrib);
*/
Escflg = ESCAPE_NONE;
break;
case '0': /* \E(0 - font1 */
case '2': /* \E(2 */
Window->G0 = 1;
/*
if (!Window->Charset)
Window->Attrib = VSgraph(Window->Attrib);
*/
Escflg = ESCAPE_NONE;
break;
default:
Escflg = ESCAPE_NONE;
break;
}
s++;
n--;
}
while ((Escflg == ESCAPE_4) && (n > 0))
{
switch (*s)
{
case 0x08:
Window->x--;
Window_Scroll(Window);
break;
case 'A': /* \E)A */
case 'B': /* \E)B */
case '1': /* \E)1 */
Window->G1 = 0;
/* if (Window->Charset)
Window->Attrib = VSnotgraph(Window->Attrib); */
Escflg = ESCAPE_NONE;
break;
case '0': /* \E)0 */
case '2': /* \E)2 */
Window->G1 = 1;
/* if (Window->Charset)
Window->Attrib = VSgraph(Window->Attrib); */
Escflg = ESCAPE_NONE;
break;
default:
Escflg = ESCAPE_NONE;
break;
}
s++;
n--;
}
while ((Escflg == ESCAPE_5) && (n > 0))
{
switch (*s)
{
case 0x08:
Window->x--;
Window_Scroll(Window);
break;
default:
Escflg = ESCAPE_NONE;
break;
}
s++;
n--;
}
/* if ((Escflg > ESCAPE_1) && (n > 0))
{
Escflg = ESCAPE_NONE;
s++;
n--;
} */
}
Window->Esc_Flag = Escflg;
if (Window->Cursor)
{
cx = Window->x * 16;
cy = 768 - Window->y * 32 - 28;
bbc_vduq(25, 4, cx % 256, cx / 256,
cy % 256, cy / 256);
bbc_vduq(25, 102, (cx + 16) % 256, (cx + 16) / 256,
(cy + 24) % 256, (cy + 24) / 256);
}
Changed_Box(-1, &Box);
if (scale)
{
r.w = Window->Window_Handle;
r.box.x0 = XtoWork(Box->box.x0) * Window->X_Mag_Mult / Window->X_Div_Mult - XtoWork(1);
r.box.x1 = XtoWork(Box->box.x1) * Window->X_Mag_Mult / Window->X_Div_Mult + XtoWork(1);
r.box.y0 = YtoWork(Box->box.y0 - SPRITE_HEIGHT) * Window->Y_Mag_Mult / Window->Y_Div_Mult - YtoWork(1);
r.box.y1 = YtoWork(Box->box.y1 - SPRITE_HEIGHT) * Window->Y_Mag_Mult / Window->Y_Div_Mult + YtoWork(1);
}
else
{
r.w = Window->Window_Handle;
r.box.x0 = XtoWork(Box->box.x0) - XtoWork(1);
r.box.x1 = XtoWork(Box->box.x1) + XtoWork(1);
r.box.y0 = YtoWork(Box->box.y0 - SPRITE_HEIGHT) - YtoWork(1);
r.box.y1 = YtoWork(Box->box.y1 - SPRITE_HEIGHT) + YtoWork(1);
}
sprite_restorestate(State);
Update_Window(Window, r);
}
static void Window_Scroll(Terminal *Window)
{
int i;
Window->y += Window->x / 80;
Window->x %= 80;
if (Window->y < Window->Top)
{
for (i = 0; i < (Window->Top - Window->y); i++)
bbc_vduq(23, 7, 0, 2, 0, 0, 0, 0, 0, 0);
Window->y = Window->Top;
}
if (Window->y > Window->Bottom)
{
for (i = 0; i < (Window->y - Window->Bottom); i++)
bbc_vduq(23, 7, 0, 3, 0, 0, 0, 0, 0, 0);
Window->y = Window->Bottom;
}
bbc_vduq(31, Window->x, Window->y);
}
static os_error *Changed_Box(int Flag, change_box **Box)
{
os_regset r;
os_error *e;
r.r[0] = Flag;
e = os_swix(OS_ChangedBox, &r);
if (e == 0)
*Box = (change_box *)(r.r[1]);
return(e);
}
void Window_Close(Terminal *Window)
{
wimp_close_wind(Window->Window_Handle);
if (Window->Session != NULL)
{
close_sess(Window->Session);
Window->Session = NULL;
}
if (!Window->Flags.flags.dont_destroy)
{
if (Window->Record != NULL)
fclose(Window->Record);
free(Window->Sprite.Area);
free(Window->Save_Area);
free(Window);
}
}
extern struct cmds cmds[];
static int keyboard(Terminal *Window, int c)
{
char Key_Buffer[10];
int Key_Length;
if ((Key_Length = keymap(Window->Session ? Window->Session->raw : FALSE, Key_Buffer, c)) == 0)
return(0);
if (Window->Session == NULL || Window->Session->echo)
Window_Write(Window, Key_Buffer, Key_Length);
if (Window->Session && Window->Session->raw)
{
(*Window->Session->parse)(Window->Session, Key_Buffer, Key_Length);
}
else
{
switch (c)
{
case '\b':
if (Window->bufptr > Window->buffer)
Window->bufptr--;
break;
case '\r':
case '\n':
if (Window->Session && !Window->Session->echo && Window->Session->parse)
Window_Write(Window, "\n", 1);
*Window->bufptr++ = '\r';
*Window->bufptr++ = '\n';
if (Window->Session && Window->Session->parse)
{
(*Window->Session->parse)(Window->Session, Window->buffer, Window->bufptr - Window->buffer);
}
else if (Window->Session == NULL)
{
cmdparse(cmds, Window->buffer, (void *) Window);
Window_Write(Window, "net> ", 5);
}
Window->bufptr = Window->buffer;
break;
default:
*Window->bufptr++ = c;
break;
}
}
return(1);
}
static void Window_Proc(wimp_eventstr *Event, void *Handle)
{
int c;
wimp_caretstr wc;
Terminal *Window = (Terminal *) Handle;
switch (Event->e)
{
case wimp_EREDRAW:
Redraw_Window(Window, Event->data.o.w);
break;
case wimp_EOPEN:
Open_Window(Window, &Event->data.o);
break;
case wimp_ECLOSE:
Window_Close(Window);
break;
case wimp_EBUT:
if (!Window->Flags.flags.no_input && Event->data.but.m.bbits != wimp_BMID)
{
wc.w = Window->Window_Handle;
wc.i = -1;
wc.height = -1;
wc.x = 0;
wc.y = 0;
wc.index = 0;
wimp_set_caret_pos(&wc);
}
break;
case wimp_EKEY:
c = Event->data.key.chcode;
if (!keyboard(Window, c))
wimp_processkey(c);
break;
/*******************************************
Adam - 17-Feb-94
Purpose: Catch drag file to windows
*******************************************/
case wimp_ESEND:
case wimp_ESENDWANTACK:
switch (Event->data.msg.hdr.action)
{
case wimp_MDATASAVE:
/* Acknowledge the DataSave message with <wimp$scrap> */
{ wimp_msgstr msg;
msg.hdr.size = 60;
msg.hdr.your_ref = Event->data.msg.hdr.my_ref;
msg.hdr.action = wimp_MDATASAVEOK;
msg.data.datasaveok.w = Event->data.msg.data.datasave.w;
msg.data.datasaveok.i = Event->data.msg.data.datasave.i;
msg.data.datasaveok.x = Event->data.msg.data.datasave.x;
msg.data.datasaveok.y = Event->data.msg.data.datasave.y;
msg.data.datasaveok.estsize = -1;
msg.data.datasaveok.type = Event->data.msg.data.datasaveok.type;
strcpy(msg.data.datasaveok.name, "<Wimp$Scrap>");
wimp_sendmessage(wimp_ESEND, &msg, Event->data.msg.hdr.task);
}
break;
case wimp_MDATALOAD:
Process_Import(Event, Window);
break;
}
break;
/*******************************************/
default:
break;
}
}
Terminal *Window_Open(struct session *Sess, char *Description, unsigned int Flags)
{
Terminal *Window;
static int clones = 0;
int Save_Area_Size;
sprite_ptr Pointer;
sprite_state sprite_state;
wimp_wstate window_state;
wimp_redrawstr r;
template *t;
if (term_type != -1)
return(NULL);
if ((Window = (Terminal *) malloc(sizeof(Terminal))) == NULL)
return(NULL);
memset(Window, 0, sizeof(Terminal));
Window->Flags.value = Flags;
if ((Window->Sprite.Area = (sprite_area *) malloc(Window->Flags.flags.sixteen ? SPRITE_SIZE_16 : SPRITE_SIZE_0)) == NULL)
{
free(Window);
return(NULL);
}
sprite_area_initialise(Window->Sprite.Area, Window->Flags.flags.sixteen ? SPRITE_SIZE_16 : SPRITE_SIZE_0);
sprite_create(Window->Sprite.Area, "screendump", sprite_nopalette, SPRITE_WIDTH, SPRITE_HEIGHT, Window->Flags.flags.sixteen ? 12 : 0);
Window->Sprite.id.tag = sprite_id_name;
Window->Sprite.id.s.name = "screendump";
sprite_select_rp(Window->Sprite.Area, &Window->Sprite.id, &Pointer);
Window->Sprite.id.tag = sprite_id_addr;
Window->Sprite.id.s.addr = Pointer;
sprite_sizeof_spritecontext(Window->Sprite.Area, &Window->Sprite.id, &Save_Area_Size);
if ((Window->Save_Area = (int *)malloc(Save_Area_Size)) == NULL)
{
free(Window->Sprite.Area);
free(Window);
return(NULL);
}
t = template_copy(template_find("Window"));
t->window.box.x0 += 40 * clones;
t->window.box.x1 += 40 * clones;
t->window.box.y0 -= 40 * clones;
t->window.box.y1 -= 40 * clones;
clones = ++clones % 5;
wimp_create_wind(&t->window, &Window->Window_Handle);
win_settitle(Window->Window_Handle, Description);
win_register_event_handler(Window->Window_Handle, Window_Proc, (void *) Window);
/* Window->Menu = menu_new("Session", ">Info,Kick,Reset,Close");
event_attachmenu(Window->Window_Handle, Window->Menu, Window_MenuProc, (void *)Window); */
Window->bufptr = Window->buffer;
Window->Save_Area[0] = 0;
if (Window->Flags.flags.sixteen)
{
Window->Foreground[ATTR_NORMAL] = 0;
Window->Background[ATTR_NORMAL] = 8;
Window->Foreground[ATTR_REVERSE] = 7;
Window->Background[ATTR_REVERSE] = 0;
Window->Foreground[ATTR_BOLD] = 9;
Window->Background[ATTR_BOLD] = 8;
Window->Foreground[ATTR_UNDER] = 10;
Window->Background[ATTR_UNDER] = 8;
Window->Foreground[ATTR_BLINK] = 11;
Window->Background[ATTR_BLINK] = 8;
}
else
{
Window->Foreground[ATTR_NORMAL] = 0;
Window->Background[ATTR_NORMAL] = 1;
Window->Foreground[ATTR_REVERSE] = 1;
Window->Background[ATTR_REVERSE] = 0;
Window->Foreground[ATTR_BOLD] = 0;
Window->Background[ATTR_BOLD] = 1;
Window->Foreground[ATTR_UNDER] = 0;
Window->Background[ATTR_UNDER] = 1;
Window->Foreground[ATTR_BLINK] = 0;
Window->Background[ATTR_BLINK] = 1;
}
sprite_outputtosprite(Window->Sprite.Area, &Window->Sprite.id, Window->Save_Area, &sprite_state);
Window_Reset(Window);
sprite_restorestate(sprite_state);
Window->Session = Sess;
if (Sess)
Window->Session->keypad = 0;
else
Window->keypad = 0;
if (!Window->Flags.flags.dont_open)
{
wimp_get_wind_state(Window->Window_Handle, &window_state);
window_state.o.behind = -1;
Open_Window(Window, &window_state.o);
if (Window->Flags.flags.caret)
{
wimp_caretstr wc;
wc.w = Window->Window_Handle;
wc.i = -1;
wc.height = -1;
wc.x = 0;
wc.y = 0;
wc.index = 0;
wimp_set_caret_pos(&wc);
}
r.w = Window->Window_Handle;
r.box.x0 = 0;
r.box.x1 = XtoWork(SPRITE_WIDTH);
r.box.y0 = -YtoWork(SPRITE_HEIGHT);
r.box.y1 = 0;
wimp_force_redraw(&r);
}
return(Window);
}
/*******************************************
Adam - 17-Feb-94
Purpose: Process drag file to windows
This routine processes files dragged to one
of the terminal windows and processes it as follows:
Drags to FTP session are converted to "put <pathname> <leafname>"
Drags to main window are convert to "source <pathname>"
In this implementation, no use has been made of in-core transfers
as they arn't really need for this, except perhaps when dragging
in from from !Edit, even then they will probably need reading
line by line - eg when I've added auto login to an ftp
or telnet site.
*******************************************/
static void Process_Import(wimp_eventstr *Event, Terminal *Window)
{
os_error *e;
os_filestr f;
int filesize;
int filetype;
char *filename;
char command[256];
filetype = xferrecv_checkinsert(&filename);
xferrecv_insertfileok();
*command = '\0'; /* No command present - yet! */
if (filetype <= 0x1000)
{
f.action = 5; /* Get file size */
f.name = filename;
e = wimpt_complain(os_file(&f));
filesize = f.start;
/* If the file has been dragged to the main window and it is a text file, source it! */
if (Window->Session==NULL && filetype==0xfff /* Text file */)
{
sprintf(command, "source %s\n", filename);
}
else if (Window->Session->type==FTP)
{
/* if FTP then do a put (will extend this to a dbox to allow remote name to be set */
sprintf(command, "put %s %s\n", filename, leafname(filename));
}
/* Send the command (if any) to the appropriate parser */
if (*command!='\0')
{
/* I have sort of copied this from key handler above... ??? */
if (Window->Session == NULL || Window->Session->echo)
Window_Write(Window, command, strlen(command));
if (Window->Session && Window->Session->parse)
(*Window->Session->parse)(Window->Session, command, strlen(command));
else if (Window->Session == NULL)
cmdparse(cmds, command, (void *) Window);
}
}
}
/* Given a RiscOS pathname, return pointer to leafname */
static char *leafname(char *s)
{
char *p;
p = s+strlen(s);
while (p>s && *p!='.' && *p!=':')
p -= 1;
return (p==s)?(p):(p+1);
}